import pdb
from tools import *

class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        if (l1 == None or l2 == None): return l1 or l2
        tmp1, tmp2 = l1, l2
        pre = None
        carry = 0
        while tmp1 and tmp2:
            tmp1.val += tmp2.val + carry
            carry = tmp1.val // 10
            tmp1.val = tmp1.val % 10
            pre = tmp1
            tmp1, tmp2 = tmp1.next, tmp2.next

        pdb.set_trace()
        if tmp2:
            tmp2.val += carry # maybe more than ten
            pre.next = tmp2
        elif tmp1:
            tmp1.val += carry
        else:
            if carry == 1:
                pre.next = ListNode(1)
        pre = pre.next
        while pre and pre.val >= 10:
            pre.val -= 10
            if pre.next:
                pre.next.val += 1
            else:
                pre.next = ListNode(1)
            pre = pre.next
        return l1

s = Solution()
s.addTwoNumbers(create_list([2]), create_list([8, 9, 9]))

